<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../sortie.php?sortie=3") ; }
 Include ($_SESSION ["repertoire_config"]."/garennes.cfg") ;
 Include ($_SESSION ["repertoire_config"]."/init.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ;
 
 Echo "<HTML><HEAD>" ;
 entete_html ("Garennes - Purge doublons", "", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Echo "</HEAD>" ;
 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"".$ligne ["couleur_texte"]."\">" ;
 Echo "<CENTER><FONT COLOR=\"#0000FF\">&nbsp;Purge&nbsp;les&nbsp;doublons&nbsp;</CENTER>" ;
 // Recherche les doublons
 $non = SQL_commande ("SELECT e.id_eleve AS id_1,f.id_eleve AS id_2,e.repere1 AS r11,e.repere2 AS r12,f.repere1 AS r21,f.repere2 AS r22,e.nom,e.prenoms,e.code_classe
                         FROM eleves e,eleves f
                        WHERE e.id_eleve!=f.id_eleve AND e.nom=f.nom AND e.prenoms=f.prenoms AND e.date_naissance=f.date_naissance
                          AND e.classe=f.classe AND e.exterieur=0 AND f.exterieur=0 AND e.millesime='".millesime (0)."' and f.millesime='".millesime (0)."'
                     ORDER BY e.repere1,f.repere1", $id_sql) ;
 echo "SELECT e.id_eleve AS id_1,f.id_eleve AS id_2,e.repere1 AS r11,e.repere2 AS r12,f.repere1 AS r21,f.repere2 AS r22,e.nom,e.prenoms,e.code_classe
                         FROM eleves e,eleves f
                        WHERE e.id_eleve!=f.id_eleve AND e.nom=f.nom AND e.prenoms=f.prenoms AND e.date_naissance=f.date_naissance
                          AND e.classe=f.classe AND e.exterieur=0 AND f.exterieur=0 AND e.millesime='".millesime (0)."' and f.millesime='".millesime (0)."'
                     ORDER BY e.repere1,f.repere1<br>" ;
Echo "------------------------------------PURGE DOUBLONS<br>" ;
 If (SQL_nbr_lignes ($non) > 0)
  {
   For ($j = 1 ; $j < SQL_nbr_lignes ($non)/2 ; $j++)
    {
     $n = SQL_tableau_associatif ($non, "") ;
     Echo "Eleve : ".$n ["nom"]." ".$n ["prenoms"].", Classe : ".$n ["code_classe"]."->" ;
     If ($n ["r11"] > 9999) { $id1 = $n ["id_1"] ; $id2 = $n ["id_2"] ; $r1 = $n ["r21"] ; $r2 = $n ["r22"] ; } Else { $id1 = $n ["id_2"] ; $id2 = $n ["id_1"] ; $r1 = $n ["r11"] ; $r2 = $n ["r12"] ; }
     //$ok = SQL_commande ("UPDATE eleves SET repere1='".$r1."',repere2='".$r2."' WHERE id_eleve='".$id1."' LIMIT 1", $id_sql) ;
     //$ok = SQL_commande ("DELETE FROM eleves WHERE id_eleve='".$id2."' LIMIT 1", $id_sql) ;
     echo "UPDATE eleves SET repere1='".$r1."',repere2='".$r2."' WHERE id_eleve='".$id1."' LIMIT 1|" ;
     echo "DELETE FROM eleves WHERE id_eleve='".$id2."' LIMIT 1<br>" ;
    }
   Echo "<BR>" ;
  }
 Echo "------------------------------------Erreur adresse<br>" ;
 $non = SQL_commande ("SELECT * FROM eleves WHERE nom_parents='AUBER' AND nom_parents_p2='MILHAC' AND millesime='".millesime (0)."'", $id_sql) ;
 If (SQL_nbr_lignes ($non) > 0)
  {
   For ($j = 1 ; $j < SQL_nbr_lignes ($non) ; $j++)
    {
     $n = SQL_tableau_associatif ($non, "") ;
     Echo "Eleve : ".$n ["nom"]." ".$n ["prenoms"].", Classe : ".$n ["code_classe"]."<BR>" ;
     //$ok = SQL_commande ("UPDATE eleves SET nom_parents='',prenom_parents='',adresse1='',adresse2='',cp='',ville='',telephone='',telephone_travail='',
     //                                       nom_parents_p2='',prenom_parents_p2='',adresse1_p2='',adresse2_p2='',cp_p2='',ville_p2='',telephone_p2='',telephone_travail_p2=''
	//		   WHERE id_eleve='".$n ["id_eleve"]."' LIMIT 1", $id_sql) ;
     echo "UPDATE eleves SET nom_parents='',prenom_parents='',adresse1='',adresse2='',cp='',ville='',telephone='',telephone_travail='',
                                            nom_parents_p2='',prenom_parents_p2='',adresse1_p2='',adresse2_p2='',cp_p2='',ville_p2='',telephone_p2='',telephone_travail_p2=''
			   WHERE id_eleve='".$n ["id_eleve"]."' LIMIT 1<br>" ;
    }
   Echo "<BR>" ;
  }
 Echo "</BODY></HTML>" ;
?>